﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;

namespace analysisText
{
    class readPDF
    {
        String pathFile;
        String textPDF;
        public readPDF(String path)
        {
            pathFile = path;
            textPDF = String.Empty;
        }

        public void readTextPDF()
        {
            PdfReader reader2 = new PdfReader(pathFile);

            for (int page = 1; page <= reader2.NumberOfPages; page++)//Lectura por paginas
            //for (int page = 102; page <= 117; page++)//Lectura por paginas
            {
                ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
                PdfReader reader = new PdfReader(pathFile); //Apertura archivo
                String bufferLectura = PdfTextExtractor.GetTextFromPage(reader, page, its);//buffer de lectura

                bufferLectura = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(bufferLectura)));//codificacion archivo
                textPDF += Environment.NewLine+"-------Hoja " + page + "-------"+Environment.NewLine;
                textPDF = textPDF + bufferLectura;
                reader.Close();
            }
        }

        public String getTextPdf()
        {
            return textPDF;
        }
    }
}
